/*
 * JGO2RDF creates a RDF representation of GAF2 files, which are automatically sourced from GO ftp site.
 * Copyright (C) 2012 Matthew M. Hindle & Artem Lysenko
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package uk.co.jgo2rdf.goa.model;

import uk.co.jgo2rdf.exception.InvalidValueException;
import uk.co.jgo2rdf.exception.ValueNotSetException;
import uk.co.jgo2rdf.goa.go.OntologyType;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * @author hindlem
 *         Date: 5/17/11
 *         Time: 10:47 AM
 * @version 0.10
 */
public class DefaultGOAEntry extends GOAUniqueMutableEntry implements Serializable {

    private static final String GO_PREFIX = "GO:";

    private String db;
    private String dbObjectId;
    private String dbObjectSymbol;
    private String qualifier;
    private int goid = -1;
    private final Set<String[]> dbReferences = new HashSet<String[]>();
    private String evidenceCode;
    private String withfrom;
    private OntologyType aspect;
    private String dbObjectName;
    private String dbObjectSynonym;
    private String dbObjectType;
    private int[] taxons;
    private Date date;
    private String assignedBy;
    private String annotationExtension;
    private String geneproductFormId;

    @Override
    public void setDB(String db) {
        this.db = db.intern();
    }

    @Override
    public void setDBObject_ID(String dbObject_id) {
        this.dbObjectId = dbObject_id;
    }

    @Override
    public void setDBObjectSymbol(String dbObjectSymbol) {
        this.dbObjectSymbol = dbObjectSymbol;
    }

    @Override
    public void setQualifier(String qualifier) {
        this.qualifier = qualifier;
    }

    @Override
    public void setGO_ID(String go_id) throws InvalidValueException {
        try {
            goid = Integer.parseInt(go_id.substring(3));
        } catch (NumberFormatException e) {
            throw new InvalidValueException(go_id);
        }
    }

    @Override
    public void addDB_References(String[] db_references) {
        this.dbReferences.add(db_references);
    }

    @Override
    public void setEvidenceCode(String evidenceCode) {
        this.evidenceCode = evidenceCode.intern();
    }

    @Override
    public void setWithFrom(String withFrom) {
        this.withfrom = withFrom;
    }

    @Override
    public void setAspect(OntologyType aspect) {
        this.aspect = aspect;
    }

    @Override
    public void setDBObjectName(String dbObjectName) {
        this.dbObjectName = dbObjectName;
    }

    @Override
    public void setDBObjectSynonym(String dbObjectSynonym) {
        this.dbObjectSynonym = dbObjectSynonym;
    }

    @Override
    public void setDBObjectType(String dbObjectType) {
        this.dbObjectType = dbObjectType;
    }

    @Override
    public void setTaxons(int[] taxons) {
        this.taxons = taxons;
    }

    @Override
    public void setDate(Date date) {
        this.date = date;
    }

    @Override
    public void setAssignedBy(String assignedBy) {
        this.assignedBy = assignedBy;
    }

    @Override
    public void setAnnotation_Extension(String annotation_extension) {
        this.annotationExtension = annotation_extension;
    }

    @Override
    public void setGeneProductFormID(String productID) {
        this.geneproductFormId = productID;
    }

    @Override
    public String getDB() {
        return db;
    }

    @Override
    public String getDBObject_ID() {
        return dbObjectId;
    }

    @Override
    public String getDBObjectSymbol() {
        return dbObjectSymbol;
    }

    @Override
    public String getQualifier() throws ValueNotSetException {
        if (qualifier == null)
            throw new ValueNotSetException("This entry has no qualifier @see hasQualifier() method");
        return qualifier;
    }

    @Override
    public boolean hasQualifier() {
        return qualifier != null;
    }

    @Override
    public int getGO_ID() {
        return goid;
    }

    @Override
    public String getGO_ID_String() {
        String number = Integer.toString(goid);
        while (number.length() < 7)
            number = '0' + number;
        return GO_PREFIX + number;
    }

    @Override
    public Set<String[]> getDB_References() {
        return dbReferences;
    }

    public void addDB_Reference(String[] refs) {
        dbReferences.add(refs);
    }

    @Override
    public String getEvidenceCode() {
        return evidenceCode;
    }

    @Override
    public String getWithFrom() {
        return withfrom;
    }

    @Override
    public boolean hasWithFrom() {
        return withfrom != null;
    }

    @Override
    public OntologyType getAspect() {
        return aspect;
    }

    @Override
    public String getDBObjectName() {
        return dbObjectName;
    }

    @Override
    public boolean hasDBObjectName() {
        return dbObjectName != null;
    }

    @Override
    public String getDBObjectSynonym() throws ValueNotSetException {
        if (dbObjectSynonym == null)
            throw new ValueNotSetException("This entry has not dbObjectSynonym @see hasDBObjectSynonym() method");
        return dbObjectSynonym;
    }

    @Override
    public boolean hasDBObjectSynonym() {
        return dbObjectSynonym != null;
    }

    @Override
    public String getDBObjectType() {
        return dbObjectType;
    }

    @Override
    public int[] getTaxons() {
        return taxons;
    }

    @Override
    public Date getDate() {
        return date;
    }

    @Override
    public String getAssignedBy() {
        return assignedBy;
    }

    @Override
    public boolean hasAssigned_By() {
        return assignedBy != null;
    }

    @Override
    public String getAnnotation_Extension() throws ValueNotSetException {
        if (annotationExtension == null)
            throw new ValueNotSetException("This entry does not have a annotation extension @see hasAnnotation_Extension() method");
        return annotationExtension;
    }

    @Override
    public boolean hasAnnotation_Extension() {
        return annotationExtension != null;
    }

    @Override
    public String getGeneProductFormID() throws ValueNotSetException {
        if (geneproductFormId == null)
            throw new ValueNotSetException("This entry does not have a gene product form id @see hasGeneProductFormID() method");
        return geneproductFormId;
    }

    @Override
    public boolean hasGeneProductFormID() {
        return geneproductFormId != null;
    }


}
